<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Contents_model short summary.
 *
 * Contents_model description.
 *
 * @version 1.0
 * @author xianbin
 */
class Contents_model extends CI_Model
{
    public $contents_id;
    public $title;
    public $contents;
    public $menuid;
    public $imgurl;
    public $keyword;
    public $description;

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function add_contents($contentsModel)
    {
        return  $this->db->insert('contents',$contentsModel);
    }

    public function get_first_row_by_menuid($menuid)
    {
        $sql="select * from contents where menuid=$menuid";
        return $this->db->query($sql)->row();
    }

    public function get_contents_by_id($contents_id)
    {
        $sql="select * from contents where contents_id=$contents_id";
        return $this->db->query($sql)->row();
    }

    public function update_contents($contentsModel)
    {
        $sql="update contents set title='$contentsModel->title',contents='$contentsModel->contents', keyword='$contentsModel->keyword',description='$contentsModel->description',imgurl='$contentsModel->imgurl' where contents_id=$contentsModel->contents_id";
        return $this->db->query($sql);
    }

    public function del_contents($contents_id)
    {
        $sql="delete from contents where contents_id=$contents_id";
        return $this->db->query($sql);
    }
}